"""
习题 41： 来自 Percal 25 号行星的哥顿人
"""

"""
一个函数也可以作为一个变量

数十年的编程下来，我在读代码的过程中已经用不到上面的三种方法了。我只要
瞟一眼就能知道它的意思。甚至给我一整页的代码，我也可以一眼瞄出里边的 
bug  和错误。这样的技能是花了超乎常人的时间和精力才锻炼得来的。在磨练
的过程中，我学会了下面三种读代码的方法，它们是用户几乎所有的编程语言： 

1.   从前向后。 
2.   从后向前。 
3.   逆时针方向。 

下次碰到难懂的语句时，你可以试试这三种方法。 
"""

from sys import exit
from random import randint

def death():
    quips = ["You died. Yout kinda suck at this.",
            "Nice job, you died ... jackass.",
            "Such a luser.",
            "I have a small puppy that's better at this."]

    print(quips[randint(0, len(quips) -1)])
    exit(1)

def central_corridor():
    print("The Gothons of Planet Percal #25 have invaded",
            "your ship and destroyed your entire crew.")
    print("You are the last surviving member and your last")
    print("mission is to get the neutron destruct bomb from")
    print("the Weapons Armory, put it in the bridge, and blow")
    print("the ship up after getting into an escape pod.")
    print("\n")
    print("""You're running down the central corridor to the
    Weapons Armory when a Gothon jumps out, red scaly skin, 
    dark grimy teeth, and evil clown costume flowing around
    his hate filled body. He's blocking the door to the Armory
    and about to pull a weapon to blast you.
    """)

    action = input("> ")

    if action == "shoot!":
        print("""Quick on the draw you yank out your blaster
        and fire it at the Gothon. His clown costume is flowing
        and moving around his body, which throws off your aim.
        Your laser hits his costume but misses him entirely.
        This completely ruins his brand new costume his mother
        bought him, which makes him fly into an insane rage and
        blast you repeatedly in the face until you are dead. 
        Then he eats you.""")
        return 'death'
    elif action == 'dodge!':
        print("""dodge!""")
        return 'death'
    elif action == "tell a joke":
        print("""tell a joke""")
        return 'laser_weapon_armory'
    else:
        print("DOES NOT COMPUTE!")
        return 'central_corridor'


def laser_weapon_armory():
    print("""weapon armory""")
    print("get the bomb, the code is 3 digits.")

    code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
    guess = input("[keypad]> ")
    guesses = 0

    while guess != code and guesses < 10:
        print("BZZZEDD!")
        guesses += 1
        guess = input("[keypad]> ")
    
    if guess == code:
        print("""opened""")
        return 'the_bridge'
    else:
        print("""...""")
        return 'death'


def the_bridge():
    print("""bridge""")

    action = input("> ")
    if action == "throw the bomb":
        print("""throw the bomb""")
        return 'death'
    elif action == 'solowly place the bomb':
        print("""place the bomb""")
        return 'the_bridge'


def escape_pod():
    print("""escape pod""")
    print("""There's 5 pods which on do you take?""")

    good_pod = randint(1, 5)
    guess = input("[pod #]> ")
    


# TODO 未完成    
    
